home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC / src / barcool.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  9.6 KB  |  345 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12. #if !defined(_WIN32_WCE_NO_CONTROLBARS)
  13.  
  14. #ifdef AFX_CORE3_SEG
  15. #pragma code_seg(AFX_CORE3_SEG)
  16. #endif
  17.  
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. #define new DEBUG_NEW
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CReBar
  27.  
  28. BEGIN_MESSAGE_MAP(CReBar, CControlBar)
  29.     //{{AFX_MSG_MAP(CReBar)
  30. WCE_DEL ON_WM_NCCREATE()
  31.     ON_WM_PAINT()
  32. WCE_DEL ON_WM_NCCALCSIZE()
  33.     ON_WM_ERASEBKGND()
  34. WCE_DEL ON_WM_NCPAINT()
  35.     ON_NOTIFY_REFLECT(RBN_HEIGHTCHANGE, OnHeightChange)
  36.     ON_NOTIFY_REFLECT(RBN_ENDDRAG, OnHeightChange)
  37.     ON_MESSAGE(RB_SHOWBAND, OnShowBand)
  38.     ON_MESSAGE_VOID(WM_RECALCPARENT, OnRecalcParent)
  39.     //}}AFX_MSG_MAP
  40. END_MESSAGE_MAP()
  41.  
  42. CReBar::CReBar()
  43. {
  44.     SetBorders();
  45. }
  46.  
  47. void CReBar::OnRecalcParent()
  48. {
  49.     CFrameWnd* pFrameWnd = GetParentFrame();
  50.     ASSERT(pFrameWnd != NULL);
  51.     pFrameWnd->RecalcLayout();
  52. }
  53.  
  54. void CReBar::OnHeightChange(NMHDR* /*pNMHDR*/, LRESULT* pResult)
  55. {
  56.     // does the CReBar have a frame?
  57.     CFrameWnd* pFrameWnd = GetParentFrame();
  58.     if (pFrameWnd != NULL)
  59.     {
  60.         // it does -- tell it to recalc its layout
  61.         if (!pFrameWnd->m_bInRecalcLayout)
  62.             pFrameWnd->RecalcLayout();
  63.         else
  64.             PostMessage(WM_RECALCPARENT);
  65.     }
  66.     *pResult = 0;
  67. }
  68.  
  69. LRESULT CReBar::OnShowBand(WPARAM wParam, LPARAM)
  70. {
  71.     LRESULT lResult = Default();
  72.     if (lResult)
  73.     {
  74.         // keep window visible state in sync with band visible state
  75.         REBARBANDINFO rbBand;
  76.         rbBand.cbSize = sizeof(rbBand);
  77.         rbBand.fMask = RBBIM_CHILD|RBBIM_STYLE;
  78.         VERIFY(DefWindowProc(RB_GETBANDINFO, wParam, (LPARAM)&rbBand));
  79.         CControlBar* pBar = DYNAMIC_DOWNCAST(CControlBar, CWnd::FromHandlePermanent(rbBand.hwndChild));
  80.         BOOL bWindowVisible;
  81.         if (pBar != NULL)
  82.             bWindowVisible = pBar->IsVisible();
  83.         else
  84.             bWindowVisible =  (::GetWindowLong(rbBand.hwndChild, GWL_STYLE) & WS_VISIBLE) != 0;
  85.         BOOL bBandVisible = (rbBand.fStyle & RBBS_HIDDEN) == 0;
  86.         if (bWindowVisible != bBandVisible)
  87.             VERIFY(::ShowWindow(rbBand.hwndChild, bBandVisible ? SW_SHOW : SW_HIDE));
  88.     }
  89.     return lResult;
  90. }
  91.  
  92. BOOL CReBar::_AddBar(CWnd* pBar, REBARBANDINFO* pRBBI)
  93. {
  94.     ASSERT_VALID(this);
  95.     ASSERT(::IsWindow(m_hWnd));
  96.     ASSERT(pBar != NULL);
  97.     ASSERT(::IsWindow(pBar->m_hWnd));
  98.  
  99.     pRBBI->cbSize = sizeof(REBARBANDINFO);
  100.     pRBBI->fMask |= RBBIM_CHILD | RBBIM_CHILDSIZE;
  101.     pRBBI->hwndChild = pBar->m_hWnd;
  102.  
  103.     CSize size;
  104.     CControlBar* pTemp = DYNAMIC_DOWNCAST(CControlBar, pBar);
  105.     if (pTemp != NULL)
  106.     {
  107.         size = pTemp->CalcFixedLayout(FALSE, m_dwStyle & CBRS_ORIENT_HORZ);
  108.     }
  109.     else
  110.     {
  111.         CRect rect;
  112.         pBar->GetWindowRect(&rect);
  113.         size = rect.Size();
  114.     }
  115. #if defined(_WIN32_WCE)
  116.     pRBBI->cxMinChild = size.cx + 4;
  117. #else // _WIN32_WCE
  118.     //WINBUG: COMCTL32.DLL is off by 4 pixels in its sizing logic.  Whatever
  119.     //    is specified as the minimum size, the system rebar will allow that band
  120.     //    to be 4 actual pixels smaller!  That's why we add 4 to the size here.
  121.     ASSERT(_afxComCtlVersion != -1);
  122.     pRBBI->cxMinChild = size.cx + (_afxComCtlVersion < VERSION_IE401 ? 4 : 0);
  123. #endif // _WIN32_WCE
  124.     pRBBI->cyMinChild = size.cy;
  125.     BOOL bResult = (BOOL)DefWindowProc(RB_INSERTBAND, (WPARAM)-1, (LPARAM)pRBBI);
  126.  
  127.     CFrameWnd* pFrameWnd = GetParentFrame();
  128.     if (pFrameWnd != NULL)
  129.         pFrameWnd->RecalcLayout();
  130.  
  131.     return bResult;
  132. }
  133.  
  134. BOOL CReBar::AddBar(CWnd* pBar, LPCTSTR pszText, CBitmap* pbmp, DWORD dwStyle)
  135. {
  136.     REBARBANDINFO rbBand;
  137.     rbBand.fMask = RBBIM_STYLE;
  138.     rbBand.fStyle = dwStyle;
  139.     if (pszText != NULL)
  140.     {
  141.         rbBand.fMask |= RBBIM_TEXT;
  142.         rbBand.lpText = const_cast<LPTSTR>(pszText);
  143.     }
  144.     if (pbmp != NULL)
  145.     {
  146.         rbBand.fMask |= RBBIM_BACKGROUND;
  147.         rbBand.hbmBack = (HBITMAP)*pbmp;
  148.     }
  149.     return _AddBar(pBar, &rbBand);
  150. }
  151.  
  152. BOOL CReBar::AddBar(CWnd* pBar, COLORREF clrFore, COLORREF clrBack, LPCTSTR pszText, DWORD dwStyle)
  153. {
  154.     REBARBANDINFO rbBand;
  155.     rbBand.fMask = RBBIM_STYLE | RBBIM_COLORS;
  156.     rbBand.fStyle = dwStyle;
  157.     rbBand.clrFore = clrFore;
  158.     rbBand.clrBack = clrBack;
  159.     if (pszText != NULL)
  160.     {
  161.         rbBand.fMask |= RBBIM_TEXT;
  162.         rbBand.lpText = const_cast<LPTSTR>(pszText);
  163.     }
  164.     return _AddBar(pBar, &rbBand);
  165. }
  166.  
  167. CSize CReBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
  168. {
  169.     ASSERT_VALID(this);
  170.     ASSERT(::IsWindow(m_hWnd));
  171.  
  172.     // the union of the band rectangles is the total bounding rect
  173.     int nCount = DefWindowProc(RB_GETBANDCOUNT, 0, 0);
  174.     REBARBANDINFO rbBand;
  175.     rbBand.cbSize = sizeof(rbBand);
  176.     int nTemp;
  177.  
  178.     // sync up hidden state of the bands
  179.     for (nTemp = nCount; nTemp--; )
  180.     {
  181.         rbBand.fMask = RBBIM_CHILD|RBBIM_STYLE;
  182.         VERIFY(DefWindowProc(RB_GETBANDINFO, nTemp, (LPARAM)&rbBand));
  183.         CControlBar* pBar = DYNAMIC_DOWNCAST(CControlBar, CWnd::FromHandlePermanent(rbBand.hwndChild));
  184.         BOOL bWindowVisible;
  185.         if (pBar != NULL)
  186.             bWindowVisible = pBar->IsVisible();
  187.         else
  188.             bWindowVisible =  (::GetWindowLong(rbBand.hwndChild, GWL_STYLE) & WS_VISIBLE) != 0;
  189.         BOOL bBandVisible = (rbBand.fStyle & RBBS_HIDDEN) == 0;
  190.         if (bWindowVisible != bBandVisible)
  191.             VERIFY(DefWindowProc(RB_SHOWBAND, nTemp, bWindowVisible));
  192.     }
  193.  
  194.     // determine bounding rect of all visible bands
  195.     CRect rectBound; rectBound.SetRectEmpty();
  196.     for (nTemp = nCount; nTemp--; )
  197.     {
  198.         rbBand.fMask = RBBIM_STYLE;
  199.         VERIFY(DefWindowProc(RB_GETBANDINFO, nTemp, (LPARAM)&rbBand));
  200.         if ((rbBand.fStyle & RBBS_HIDDEN) == 0)
  201.         {
  202.             CRect rect;
  203.             VERIFY(DefWindowProc(RB_GETRECT, nTemp, (LPARAM)&rect));
  204.             rectBound |= rect;
  205.         }
  206.     }
  207.  
  208.     // add borders as part of bounding rect
  209.     if (!rectBound.IsRectEmpty())
  210.     {
  211.         CRect rect; rect.SetRectEmpty();
  212.         CalcInsideRect(rect, bHorz);
  213.         rectBound.right -= rect.Width();
  214.         rectBound.bottom -= rect.Height();
  215.     }
  216.  
  217.     return CSize((bHorz && bStretch) ? 32767 : rectBound.Width(),
  218.                  (!bHorz && bStretch) ? 32767 : rectBound.Height());
  219. }
  220.  
  221. CSize CReBar::CalcDynamicLayout(int /*nLength*/, DWORD dwMode)
  222. {
  223.     if (dwMode & LM_HORZDOCK)
  224.         ASSERT(dwMode & LM_HORZ);
  225.     return CalcFixedLayout(dwMode & LM_STRETCH, dwMode & LM_HORZ);
  226. }
  227.  
  228. BOOL CReBar::Create(CWnd* pParentWnd, DWORD dwCtrlStyle, DWORD dwStyle, UINT nID)
  229. {
  230.     ASSERT_VALID(pParentWnd);   // must have a parent
  231.     ASSERT (!((dwStyle & CBRS_SIZE_FIXED) && (dwStyle & CBRS_SIZE_DYNAMIC)));
  232.  
  233.     // save the style
  234.     m_dwStyle = (dwStyle & CBRS_ALL);
  235.     if (nID == AFX_IDW_REBAR)
  236.         m_dwStyle |= CBRS_HIDE_INPLACE;
  237.  
  238.     dwStyle &= ~CBRS_ALL;
  239.     dwStyle |= CCS_NOPARENTALIGN|CCS_NOMOVEY|CCS_NODIVIDER|CCS_NORESIZE|RBS_VARHEIGHT;
  240.     dwStyle |= dwCtrlStyle;
  241.  
  242.     // initialize common controls
  243.     VERIFY(AfxDeferRegisterClass(AFX_WNDCOMMCTL_COOL_REG));
  244. #if !defined(_WIN32_WCE)
  245.     _AfxGetComCtlVersion();
  246.     ASSERT(_afxComCtlVersion != -1);
  247. #endif // _WIN32_WCE
  248.  
  249.     // create the HWND
  250.     CRect rect; rect.SetRectEmpty();
  251.     if (!CWnd::Create(REBARCLASSNAME, NULL, dwStyle, rect, pParentWnd, nID))
  252.         return FALSE;
  253.  
  254.     // Note: Parent must resize itself for control bar to be resized
  255.  
  256.     return TRUE;
  257. }
  258.  
  259. void CReBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHandler)
  260. {
  261.     UpdateDialogControls(pTarget, bDisableIfNoHandler);
  262. }
  263.  
  264. #if !defined(_WIN32_WCE)
  265. BOOL CReBar::OnNcCreate(LPCREATESTRUCT lpCreateStruct)
  266. {
  267.     if (!CControlBar::OnNcCreate(lpCreateStruct))
  268.         return FALSE;
  269.  
  270.     // if the owner was set before the rebar was created, set it now
  271.     if (m_hWndOwner != NULL)
  272.         DefWindowProc(RB_SETPARENT, (WPARAM)m_hWndOwner, 0);
  273.  
  274.     return TRUE;
  275. }
  276. #endif // _WIN32_WCE
  277.  
  278. BOOL CReBar::OnEraseBkgnd(CDC*)
  279. {
  280.     return (BOOL)Default();
  281. }
  282.  
  283. #if !defined(_WIN32_WCE)
  284. void CReBar::OnNcCalcSize(BOOL /*bCalcValidRects*/, NCCALCSIZE_PARAMS* lpncsp)
  285. {
  286.     // calculate border space (will add to top/bottom, subtract from right/bottom)
  287.     CRect rect; rect.SetRectEmpty();
  288.     BOOL bHorz = (m_dwStyle & CBRS_ORIENT_HORZ) != 0;
  289.     CControlBar::CalcInsideRect(rect, bHorz);
  290.  
  291.     // adjust non-client area for border space
  292.     lpncsp->rgrc[0].left += rect.left;
  293.     lpncsp->rgrc[0].top += rect.top;
  294.     lpncsp->rgrc[0].right += rect.right;
  295.     lpncsp->rgrc[0].bottom += rect.bottom;
  296. }
  297.  
  298. void CReBar::OnNcPaint()
  299. {
  300.     EraseNonClient();
  301. }
  302. #endif // _WIN32_WCE
  303.  
  304. void CReBar::OnPaint()
  305. {
  306.     Default();
  307. }
  308.  
  309. #if !defined(_WIN32_WCE_NO_TOOLTIPS)
  310. int CReBar::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
  311. {
  312.     ASSERT_VALID(this);
  313.     ASSERT(::IsWindow(m_hWnd));
  314.  
  315.     HWND hWndChild = _AfxChildWindowFromPoint(m_hWnd, point);
  316.     CWnd* pWnd = CWnd::FromHandlePermanent(hWndChild);
  317.     if (pWnd == NULL)
  318.         return CControlBar::OnToolHitTest(point, pTI);
  319.  
  320.     ASSERT(pWnd->m_hWnd == hWndChild);
  321.     return pWnd->OnToolHitTest(point, pTI);
  322. }
  323.  
  324. LRESULT CReBar::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  325. {
  326.     // special handling for certain messages (forwarding to owner/parent)
  327.     switch (message)
  328.     {
  329.     case WM_POPMESSAGESTRING:
  330.     case WM_SETMESSAGESTRING:
  331.         return GetOwner()->SendMessage(message, wParam, lParam);
  332.     }
  333.     return CControlBar::WindowProc(message, wParam, lParam);
  334. }
  335. #endif // _WIN32_WCE_NO_TOOLTIPS
  336.  
  337. #ifdef AFX_INIT_SEG
  338. #pragma code_seg(AFX_INIT_SEG)
  339. #endif
  340.  
  341. IMPLEMENT_DYNAMIC(CReBar, CControlBar)
  342.  
  343. /////////////////////////////////////////////////////////////////////////////
  344. #endif // _WIN32_WCE_NO_CONTROLBARS
  345.